package com.sec.android.app.myfiles.module.download;

import android.content.Context;

import com.sec.android.app.myfiles.facade.FacadeItem;
import com.sec.android.app.myfiles.fragment.AbsMyFilesFragment;
import com.sec.android.app.myfiles.fragment.home.HomeFragment;
import com.sec.android.app.myfiles.fragment.home.HomeFragmentItem;
import com.sec.android.app.myfiles.module.ContentObservable;
import com.sec.android.app.myfiles.module.abstraction.AbsContentObserverImp;
import com.sec.android.app.myfiles.module.abstraction.AbsDragAndDrop;
import com.sec.android.app.myfiles.module.abstraction.AbsFileListAdapterImp;
import com.sec.android.app.myfiles.module.abstraction.AbsFileOperationImp;
import com.sec.android.app.myfiles.module.abstraction.AbsMenuImp;
import com.sec.android.app.myfiles.module.abstraction.AbsModuleLoaderImp;
import com.sec.android.app.myfiles.module.abstraction.AbsProviderImp;
import com.sec.android.app.myfiles.module.abstraction.AbsReloadStrategyImp;
import com.sec.android.app.myfiles.module.abstraction.FileRecord;
import com.sec.android.app.myfiles.module.abstraction.FileRecord.StorageType;
import com.sec.android.app.myfiles.module.download.cmd.ClearHistoryCmd;
import com.sec.android.app.myfiles.module.download.cmd.DownloadConfirmCmd;
import com.sec.android.app.myfiles.module.download.cmd.OmaConfirmCmd;
import com.sec.android.app.myfiles.navigation.NavigationInfo;
import com.sec.android.app.myfiles.navigation.NavigationInfo.NavigationMode;
import com.sec.android.app.myfiles.operation.ProgressListener;
import com.sec.android.app.myfiles.provider.DbTableInfo;
import com.sec.android.app.myfiles.widget.listview.AbsListViewImp;

import java.util.ArrayList;

public class DownloadModuleLoaderImp extends AbsModuleLoaderImp {
    @Override
    protected FileRecord _createFileRecord(String fullPath) {
        return new DownloadFileRecord(fullPath);
    }

    @Override
    protected FileRecord _createFileRecord(int id, String path, String name, long size, long date, int fileType, int isHidden, int itemCount,
                                           int itemCountHidden) {
        return new DownloadFileRecord(FileRecord.getFullPath(path, name));
    }

    @Override
    protected AbsFileListAdapterImp _createAdapterImp(Context context, NavigationInfo navigationInfo, AbsListViewImp listView) {
        return new DownloadListAdapterImp(context, navigationInfo, listView, null, 0);
    }

    @Override
    protected AbsProviderImp _createProviderImp(Context context) {
        return new DownloadProviderImp(context);
    }

    @Override
    protected DbTableInfo _getTableInfoImp() {
        return DownloadDbTableInfo.getInstance();
    }

    @Override
    protected AbsMenuImp _createMenuImp(Context context, StorageType supportStorage) {
        return new DownloadMenuImp(context, supportStorage);
    }

    @Override
    protected AbsFileOperationImp _createFileOperationImp(Context context, ProgressListener listener) {
        return new DownloadOperationImp(context, listener);
    }

    @Override
    protected void _createHomeItem(Context context, HomeFragment fragment, ArrayList<HomeFragmentItem> itemList, boolean isLeftPanel) {
        NavigationInfo info = fragment.getNavigationInfo();

        if (info != null && (info.getNavigationMode() == NavigationMode.Normal || info.getNavigationMode() == NavigationMode.Pick_files)) {
            HomeFragmentItem item = new DownloadHomeItem(context, fragment);
            itemList.add(item);
        }
    }

    @Override
    protected StorageType getSupportStorage() {
        return StorageType.Downloads;
    }

    @Override
    protected void _addFacadeItemList(ArrayList<FacadeItem> facadeItem) {
        facadeItem.add(FacadeItem.createFacadeItem(FacadeItem.CLEAR_DOWNLOAD_HISTORY, new ClearHistoryCmd()));
        facadeItem.add(FacadeItem.createFacadeItem(FacadeItem.DOWNLOAD_CONFIRM, new DownloadConfirmCmd()));
        facadeItem.add(FacadeItem.createFacadeItem(FacadeItem.OMA_CONFIRM, new OmaConfirmCmd()));
    }

    @Override
    protected AbsContentObserverImp _createContentObserver(Context context, FileRecord record, ContentObservable updater) {
        return new DownloadObserverImp(context, record, updater);
    }

    @Override
    protected AbsReloadStrategyImp _createReloadStrategy(Context context, NavigationInfo navigationInfo) {
        return new DownloadReloadStrategyImp(context, navigationInfo);
    }

    @Override
    protected AbsDragAndDrop _getDragAndDropImp(AbsMyFilesFragment fragment, AbsListViewImp listViewImp) {
        return new DownloadDragAndDropImp(fragment, listViewImp);
    }
}
